package servlet;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import bean.weiboBean;
import pojo.Weibo;

/**
 * Servlet implementation class indexsvl
 */
@WebServlet("/indexsvl")
public class indexsvl extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public indexsvl() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
request.setCharacterEncoding("utf-8");
		
		HttpSession session =request.getSession(false);
		weiboBean wbb = new weiboBean();	
		Weibo wb = new Weibo();
		ArrayList list = new ArrayList();
		//ArrayList forwordlist = new ArrayList();
		list = wbb.selectWeibo(50);	
		System.out.println("list.size"+list.size());
		request.setAttribute("weibo", list);	
		int userid = 0;
		if(session != null){
			//wb = (Weibo) list.get(0);
			//forwordlist = wbb.selectForwordWeibo(wb.getWeiboid());
			//System.out.println(wb.getWeiboid());
			Object iid = session.getAttribute("userId");
			if(iid!=null){
				 userid = (int)iid;
			}	
			ArrayList focusList = new ArrayList();
			focusList = wbb.selectFocus(userid);
			request.setAttribute("focusList", focusList);
			//request.setAttribute("forwordlist", forwordlist);
			
		}
//			int loginUserid = (int)session.getAttribute("uid");
//			int weiboUserid = (int)session.getAttribute("weiboUserid");
//			try {
//				if(wbb.isFocus(weiboUserid, loginUserid)){
//				 flag = true;
//					session.setAttribute("isFocus", flag);
//				}else{
//					session.setAttribute("isFocus", flag);
//				}
//			} catch (SQLException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//		}		
		request.getRequestDispatcher("index.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
